package com.uchonor.api.interceptor;

import com.uchonor.olight.agent.module.web.IWebUtils;
import com.uchonor.olight.agent.module.web.vo.UserInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.ssssssss.magicapi.modules.db.inteceptor.NamedTableInterceptor;
import org.ssssssss.magicapi.modules.db.model.SqlMode;
import org.ssssssss.magicapi.modules.db.table.NamedTable;

@Component
public class CustomNamedTableInterceptor implements NamedTableInterceptor {

    @Autowired
    private IWebUtils iWebUtils;

    /*
     * 执行单表操作之前
     */
    @Override
    public void preHandle(SqlMode sqlMode, NamedTable namedTable) {
        try {
            UserInfoVo userInfoVo = iWebUtils.getUserInfo();
            if (userInfoVo != null && StringUtils.isNotBlank(userInfoVo.getUserId()))
                if (sqlMode == SqlMode.INSERT) {
                    // TODO,新增或者修改添加自动的proId和tenantId
//                    namedTable.getColumns();
//                    namedTable.column("create_by", UserUtils.getId());
                } else if (sqlMode == SqlMode.UPDATE) {

                }
        } catch (Exception e) {
        }
    }
}